﻿using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using RecruitStudents.Client.BLL;
using RecruitStudents.Client.Report;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Const;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Appointment
{
    public partial class Appointment_MakeAppointmentForm_First_List : BaseForm
    {
        #region 读卡器
        public int iRetUSB = 0;
        public int iRetCOM = 0;

        public StringBuilder name;      //姓名
        public String sex;              //性别
        public String people;           //民族，护照识别时此项为空
        public String birthday;         //出生日期
        public String address;          //地址，在识别护照时导出的是国籍简码
        public string number;           //地址，在识别护照时导出的是国籍简码
        public string signdate;         //签发日期，在识别护照时导出的是有效期至 
        public string validtermOfStart; //有效起始日期，在识别护照时为空
        public string validtermOfEnd;   //有效截止日期，在识别护照时为空

        //扫描结构：
        [StructLayout(LayoutKind.Sequential, Size = 16, CharSet = CharSet.Ansi)]
        public struct IDCARD_ALL
        {
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 30)]
            public char name;               //姓名
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)]
            public char sex;                //性别
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
            public char people;             //民族，护照识别时此项为空
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
            public char birthday;           //出生日期
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 70)]
            public char address;            //地址，在识别护照时导出的是国籍简码
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 36)]
            public char number;             //地址，在识别护照时导出的是国籍简码
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 30)]
            public char signdate;           //签发日期，在识别护照时导出的是有效期至 
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
            public char validtermOfStart;   //有效起始日期，在识别护照时为空
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
            public char validtermOfEnd;     //有效截止日期，在识别护照时为空
        }

        private void InitCardData()
        {
            try
            {
                int iPort;
                for (iPort = 1001; iPort <= 1016; iPort++)
                {
                    iRetUSB = CheckIDCard.CVR_InitComm(iPort);
                    if (iRetUSB == 1)
                        break;
                }

                for (iPort = 1; iPort <= 4; iPort++)
                {
                    iRetCOM = CheckIDCard.CVR_InitComm(iPort);
                    if (iRetCOM == 1)
                        break;
                }

                if ((iRetCOM == 1) || (iRetUSB == 1))
                {
                    this.groupSFZ.Text = "设置、扫描区（初始化成功）";
                }
                else
                {
                    this.groupSFZ.Text = "设置、扫描区（初始化失败）";
                }
            }
            catch
            {

            }
        }

        #endregion
        ServiceComm serviceComm = new ServiceComm();
        ServiceAppointment service = new ServiceAppointment();
        ServiceExaminee serviceExaminee = new ServiceExaminee();
        public Appointment_MakeAppointmentForm_First_List()
        {
            InitializeComponent();
            InitCardData();
            txtIdCard.KeyPress += txtIdCard_KeyPress;
            InitAppointment();
            ClearTextBox();
        }

        #region 身份证输入框回车事件
        private void txtIdCard_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (CheckIDCard.CheckTextEditIdCardNo(txtIdCard, e))
            {
                txtIdCard_Query.Text = txtIdCard.Text;
                CheckAppointmentStudents(txtIdCard.Text);
            }
        }

        string SignUpID = string.Empty;
        private void CheckAppointmentStudents(string strIdCard)
        {
            gdAppointmentStudents.DataSource = null;
            gridControl1.DataSource = null;
            DataTable dt = service.CheckStudentAppointmentDataTable_First_New(strIdCard, SessionerHelper.ExamPlaceID, SessionerHelper.SpecialityKindsNO,
                SessionerHelper.ExamLevel, SessionerHelper.SystemYear);
            if (dt == null || dt.Rows.Count < 1)
            {
                ClearTextBox();
                txtIdCard.Text = strIdCard;
                DevHelper.ShowErrorMessageBox("无该考生报名信息！");
            }
            else
            {
                //if (dt.Rows[0]["AllowExamID"].ToString().Trim() == "")
                //{
                //    ClearTextBox();
                //    DevHelper.ShowErrorMessageBox("该考生的准考证号为空！");
                //    return;
                //}

                //if (!ConstAppConfig.YJF_Value.Equals(dt.Rows[0]["IsFee"].ToString()))
                //{
                //    ClearTextBox();
                //    DevHelper.ShowInfoMessageBox("该考生" + ConstAppConfig.WJF + "！");
                //}
                if (dt.Rows[0]["AllowExamID"].ToString().Trim() != "")
                {
                    ClearTextBox();
                    DevHelper.ShowErrorMessageBox("该考生的已经进行了现场确认！");
                    return;
                }

                SignUpID = dt.Rows[0]["SignUpID"].ToSafeString();
                lbGuid.Text = SignUpID;
                try
                {
                    using (DataSet ds = serviceExaminee.GetStudentsPhoto(SignUpID))
                    {
                        if (ds != null && ds.Tables[0].Rows.Count > 0)
                        {
                            byte[] bytes = (byte[])ds.Tables[0].Rows[0]["Photo"];
                            using (MemoryStream ms = new MemoryStream(bytes))
                            {
                                Image img = Image.FromStream(ms);
                                ms.Close();
                                this.pictureBox1.Image = img;
                            }
                        }
                    }
                }
                catch
                { }
                //lbGuid.Text = dt.Rows[0]["SignUpStudentsSpecialityID"].ToString().Trim();
                lbCXJG.Text = "查询成功。";
                lbKSZG.Text = dt.Rows[0]["IsActive"].ToString().Equals("1") ? "有效" : "无效";
                using (DataTable dtExamLevel = serviceComm.GetExamLevelTable())
                {
                    DataRow[] drs = dtExamLevel.Select("DicNO='" + SessionerHelper.ExamLevel + "'");
                    if (drs.Length > 0)
                    {
                        lbKSJB.Text = drs[0]["DicName"].ToSafeString();
                    }
                }
                lbXM.Text = dt.Rows[0]["Name"].ToString().Trim();
                lbSFZH.Text = dt.Rows[0]["IdentityCard"].ToString().Trim();
                lbKSH.Text = dt.Rows[0]["NMT_SignUpID"].ToString().Trim();
                lbZKZH.Text = dt.Rows[0]["AllowExamID"].ToString().Trim();
                using (DataTable dtExamLevel = serviceComm.GetDicDataTableByDicTableName("TB_Dic_ExamProvince"))
                {
                    DataRow[] drs = dtExamLevel.Select("DicNO='" + dt.Rows[0]["ExamProvince"].ToString().Trim() + "'");
                    if (drs.Length > 0)
                    {
                        lbSYD.Text = drs[0]["DicName"].ToSafeString();
                    }
                }
                lbLXDH.Text = dt.Rows[0]["LinkMobile"].ToString().Trim();
                //TB_Sys_ExamPlaceSpecialityKindsGroupMapping modelGroup = service.GetAppointmentGroupTypeName_First(dt.Rows[0]["AppointmentGroup"] != null ? dt.Rows[0]["AppointmentGroup"].ToString() : "");
                //if (modelGroup != null)
                //{
                //    lbYYZB.Text = modelGroup.GroupName;
                //}
                lbYYSJ.Text = dt.Rows[0]["AppointmentGroupTime"] != null ? dt.Rows[0]["AppointmentGroupTime"].ToString() : "";
                lbJFZT.Text = ConstAppConfig.GetIsFee(dt.Rows[0]["IsFee"].ToString());
                //this.btn_Appointment.Focus();

                gridControl1.DataSource = service.GetCheckStudentAppointmentDataTable_First_New(strIdCard, SessionerHelper.ExamPlaceID, SessionerHelper.ExamLevel, SessionerHelper.SystemYear);
                this.InitAppointmentStudents();
            }
        }
        #endregion

        private void ClearTextBox()
        {
            txtIdCard_Query.Text = "";
            txtName_Query.Text = "";
            txtIdCard.Text = "";
            lbGuid.Text = "";
            lbCXJG.Text = "";
            lbKSZG.Text = "";
            lbKSJB.Text = "";
            lbXM.Text = "";
            lbSFZH.Text = "";
            lbKSH.Text = "";
            lbZKZH.Text = "";
            lbSYD.Text = "";
            lbLXDH.Text = "";
            lbYYZB.Text = "";
            lbYYSJ.Text = "";
            lbJFZT.Text = "";
            pictureBox1.Image = null;

        }

        private void ShowLotteryForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            timer_ReadID.Enabled = false;
        }

        private void InitAppointment()
        {
            //InitAppointmentStudents();
            //try
            //{
            //    using (DataTable dt = service.GetAppointmentTypeDataTable_First(SessionerHelper.ExamPlaceID, SessionerHelper.SpecialityKindsNO, SessionerHelper.ExamLevel))
            //    {
            //        gdAppointment.DataSource = dt;
            //        if (dt != null && dt.Rows.Count > 0)
            //        {
            //            InitAppointmentStudents();
            //        }
            //        else
            //        {
            //            gdAppointmentStudents.DataSource = null;
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    DevHelper.ShowErrorMessageBox(ex.Message);
            //}
        }

        private void InitAppointmentStudents()
        {
            try
            {
                if (txtIdCard_Query.Text == "" && txtName_Query.Text == "")
                {
                    gdAppointmentStudents.DataSource = null;
                }
                else
                {
                    DataTable dt = service.GetAppointmentStudentDataTable_First_New(SessionerHelper.ExamPlaceID, SessionerHelper.SpecialityKindsNO,
                        SessionerHelper.ExamLevel, SessionerHelper.SystemYear, txtName_Query.Text, txtIdCard_Query.Text);
                    gdAppointmentStudents.DataSource = dt;
                }
                //var strGroupNo = gridView1.GetFocusedRowCellValue("GroupNo").ToString();
                //using (DataTable dt = service.GetAppointmentStudentDataTable_First(strGroupNo, SessionerHelper.ExamPlaceID, SessionerHelper.SpecialityKindsNO, SessionerHelper.ExamLevel))
                //{
                //    gdAppointmentStudents.DataSource = dt;
                //    if (dt != null)
                //    {
                //        if (gridView1.FocusedRowHandle >= 0)
                //            gridView1.SetRowCellValue(gridView1.FocusedRowHandle, ActualAcount, dt.Rows.Count);
                //    }
                //    else
                //    {
                //        if (gridView1.FocusedRowHandle >= 0)
                //            gridView1.SetRowCellValue(gridView1.FocusedRowHandle, ActualAcount, 0);
                //    }
                //}
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox(ex.Message);
            }
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                GridView gridView = (GridView)sender;
                if (DevHelper.IsDoubleClick(gridView))
                {
                    InitAppointmentStudents();
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox(ex.Message);
            }
        }

        private void gridView1_CustomDrawEmptyForeground(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e)
        {
            try
            {
                GridView gridView = (GridView)sender;
                if (DevHelper.IsDoubleClick(gridView))
                {
                    InitAppointmentStudents();
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox(ex.Message);
            }
        }

        private void gridView2_DoubleClick(object sender, EventArgs e)
        {
            if (gridView2.GetFocusedValue() != null)
            {
                if (XtraMessageBox.Show("是否要重新打印该考生的准考证？", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
                {
                    var strAllowExamID = gridView2.GetFocusedRowCellValue("AllowExamID").ToString();
                    var strIdentityCard = gridView2.GetFocusedRowCellValue("IdentityCard").ToString();
                    DataTable dtPrint = service.GetStudentAppointmentDataTable_Print(strIdentityCard, SessionerHelper.ExamPlaceID,
                        SessionerHelper.SpecialityKindsNO, SessionerHelper.ExamLevel, SessionerHelper.SystemYear).Tables[0];
                    if (dtPrint != null && dtPrint.Rows.Count > 0)
                    {
                        DataTable dtPrintNew = null;
                        foreach (DataRow dr in dtPrint.Rows)
                        {
                            if (dr["AllowExamID"].ToSafeString() == strAllowExamID)
                            {
                                dtPrintNew = new DataTable();
                                dtPrintNew = dtPrint.Clone();
                                if (dr["Sex"].ToSafeString() == "1")
                                {
                                    dr["Sex"] = "男";
                                }
                                else
                                {
                                    dr["Sex"] = "女";
                                }
                                dtPrintNew.Rows.Add(dr.ItemArray);
                                string strTitle = SessionerHelper.SystemYear + "年上海市{0}类专业统考确认单";
                                string strSubTitle = SessionerHelper.SystemYear + "年上海市普通高等院校{0}类专业统考";
                                string strRemark = "此证须经加盖{0}类统考考务专用章后方有效。";
                                if (dr["SpecialityKindsName"].ToSafeString() == "播音与主持")
                                {
                                    strRemark = "此证须经加盖{0}艺术统考考务专用章后方有效。";
                                    strTitle = SessionerHelper.SystemYear + "年上海市{0}艺术专业统考确认单";
                                    strSubTitle = SessionerHelper.SystemYear + "年上海市普通高等院校{0}艺术专业统考";
                                }
                                //strTitle = string.Format(strTitle, SessionerHelper.SpecialityKinds);
                                //strSubTitle = string.Format(strSubTitle, SessionerHelper.SpecialityKinds);
                                strTitle = string.Format(strTitle, dr["SpecialityKindsName"].ToSafeString());
                                strSubTitle = string.Format(strSubTitle, dr["SpecialityKindsName"].ToSafeString());
                                strRemark = string.Format(strRemark, dr["SpecialityKindsName"].ToSafeString());
                                Report_Print print = new Report_Print(dtPrintNew, strTitle, strSubTitle, strRemark);
                                print.Width = 700;
                                print.ShowDialog();
                            }
                        }
                    }
                }
                //if (XtraMessageBox.Show("是否确认取消该考生的预约信息？", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
                //{
                //    //var strGroupNo = gridView1.GetFocusedRowCellValue("GroupNo").ToString();
                //    var signUpStudentsSpecialityId = gridView2.GetFocusedRowCellValue("SignUpStudentsSpecialityID").ToString();
                //    service.CancelAppointment_First(signUpStudentsSpecialityId, strGroupNo);
                //    InitAppointmentStudents();
                //}
            }
        }

        private void btn_Appointment_Click(object sender, EventArgs e)
        {
            List<string> list = new List<string>();
            List<string> listSpec = new List<string>();
            string strSignUpID = string.Empty;
            string strIdentityCard = string.Empty;
            for (int i = 0; i < gridView1.RowCount; i++)
            {
                string val = gridView1.GetRowCellValue(i, gridView1.Columns["IsSelect"]).ToSafeString().ToLower();
                if (val == "true")
                {
                    strSignUpID = gridView1.GetRowCellValue(i, gridView1.Columns["SignUpID"]).ToString();
                    strIdentityCard = gridView1.GetRowCellValue(i, gridView1.Columns["IdentityCard"]).ToString();
                    string strSpecialityKindsID = gridView1.GetRowCellValue(i, gridView1.Columns["SpecialityKindsID"]).ToString();
                    string strSpecialityKindsName = gridView1.GetRowCellValue(i, gridView1.Columns["SpecialityKindsName"]).ToString();
                    list.Add(strSpecialityKindsID);
                    listSpec.Add(strSpecialityKindsName);
                }
            }
            if (list.Count == 0)
            {
                DevHelper.ShowErrorMessageBox("请先选择待确认考生数据，然后点击预约！");
                return;
            }
            else
            {
                try
                {
                    timer_ReadID.Enabled = false;
                    foreach (string strSpec in list)
                    {
                        service.MakeAppointment_First_New(strSignUpID, SessionerHelper.ExamPlaceID, strSpec, SessionerHelper.ExamLevel, SessionerHelper.SystemYear);
                    }
                    //SaveIDCardInfo(SignUpID);
                    DataTable dtPrint = service.GetStudentAppointmentDataTable_Print(strIdentityCard, SessionerHelper.ExamPlaceID,
                        SessionerHelper.SpecialityKindsNO, SessionerHelper.ExamLevel, SessionerHelper.SystemYear).Tables[0];
                    if (dtPrint != null && dtPrint.Rows.Count > 0)
                    {
                        DataTable dtPrintNew = null;
                        foreach (DataRow dr in dtPrint.Rows)
                        {
                            if (listSpec.Contains(dr["SpecialityKindsName"].ToSafeString()))
                            {
                                dtPrintNew = new DataTable();
                                dtPrintNew = dtPrint.Clone();
                                if (dr["Sex"].ToSafeString() == "1")
                                {
                                    dr["Sex"] = "男";
                                }
                                else
                                {
                                    dr["Sex"] = "女";
                                }
                                dtPrintNew.Rows.Add(dr.ItemArray);
                                string strTitle = SessionerHelper.SystemYear + "年上海市{0}类专业统考确认单";
                                string strSubTitle = SessionerHelper.SystemYear + "年上海市普通高等院校{0}类专业统考";
                                string strRemark = "此证须经加盖{0}类统考考务专用章后方有效。";
                                if (dr["SpecialityKindsName"].ToSafeString() == "播音与主持")
                                {
                                    strRemark = "此证须经加盖{0}艺术统考考务专用章后方有效。";
                                    strTitle = SessionerHelper.SystemYear + "年上海市{0}艺术专业统考确认单";
                                    strSubTitle = SessionerHelper.SystemYear + "年上海市普通高等院校{0}艺术专业统考";
                                }
                                //strTitle = string.Format(strTitle, SessionerHelper.SpecialityKinds);
                                //strSubTitle = string.Format(strSubTitle, SessionerHelper.SpecialityKinds);
                                strTitle = string.Format(strTitle, dr["SpecialityKindsName"].ToSafeString());
                                strSubTitle = string.Format(strSubTitle, dr["SpecialityKindsName"].ToSafeString());
                                strRemark = string.Format(strRemark, dr["SpecialityKindsName"].ToSafeString());
                                Report_Print print = new Report_Print(dtPrintNew, strTitle, strSubTitle, strRemark);
                                print.Width = 700;
                                print.ShowDialog();
                            }
                        }
                        this.gridControl1.DataSource = null;
                        txtIdCard.Text = string.Empty;
                        InitAppointmentStudents();
                        ClearTextBox();
                    }
                }
                catch
                { }
                timer_ReadID.Enabled = true;




                //if (lbGuid.Text == "")
                //{
                //    DevHelper.ShowErrorMessageBox("请先刷考生身份证进行确认！");
                //    return;
                //}
                //try
                //{
                //    timer_ReadID.Enabled = false;
                //    service.MakeAppointment_First_New(lbGuid.Text, SessionerHelper.ExamPlaceID, SessionerHelper.SpecialityKindsNO, SessionerHelper.ExamLevel, SessionerHelper.SystemYear);
                //    SaveIDCardInfo(SignUpID);
                //    InitAppointmentStudents();
                //    DataTable dtPrint = service.GetStudentAppointmentDataTable_Print(txtIdCard.Text, SessionerHelper.ExamPlaceID,
                //        SessionerHelper.SpecialityKindsNO, SessionerHelper.ExamLevel, SessionerHelper.SystemYear).Tables[0];
                //    if (dtPrint != null && dtPrint.Rows.Count > 0)
                //    {
                //        DataTable dtPrintNew = null;
                //        foreach (DataRow dr in dtPrint.Rows)
                //        {
                //            dtPrintNew = new DataTable();
                //            dtPrintNew = dtPrint.Clone();
                //            if (dr["Sex"].ToSafeString() == "1")
                //            {
                //                dr["Sex"] = "男";
                //            }
                //            else
                //            {
                //                dr["Sex"] = "女";
                //            }
                //            dtPrintNew.Rows.Add(dr.ItemArray);
                //            string strTitle = SessionerHelper.SystemYear + "年上海市{0}类专业统考确认单";
                //            string strSubTitle = SessionerHelper.SystemYear + "年上海市普通高等院校{0}类专业统考";
                //            string strRemark = "此证须经加盖{0}类统考考务专用章后方有效。";
                //            if (dr["SpecialityKindsName"].ToSafeString() == "播音与主持")
                //            {
                //                strRemark = "此证须经加盖{0}艺术统考考务专用章后方有效。";
                //                strTitle = SessionerHelper.SystemYear + "年上海市{0}艺术专业统考确认单";
                //                strSubTitle = SessionerHelper.SystemYear + "年上海市普通高等院校{0}艺术专业统考";
                //            }
                //            //strTitle = string.Format(strTitle, SessionerHelper.SpecialityKinds);
                //            //strSubTitle = string.Format(strSubTitle, SessionerHelper.SpecialityKinds);
                //            strTitle = string.Format(strTitle, dr["SpecialityKindsName"].ToSafeString());
                //            strSubTitle = string.Format(strSubTitle, dr["SpecialityKindsName"].ToSafeString());
                //            strRemark = string.Format(strRemark, dr["SpecialityKindsName"].ToSafeString());
                //            Report_Print print = new Report_Print(dtPrintNew, strTitle, strSubTitle, strRemark);
                //            print.Width = 700;
                //            print.ShowDialog();
                //        }
                //    }
                //    ClearTextBox();
                //}
                //catch
                //{

                //}
                //timer_ReadID.Enabled = true;



                //var strGroupNo = (gridView1.GetFocusedRowCellValue("GroupNo") ?? "").ToString();
                //var strGroupName = (gridView1.GetFocusedRowCellValue("GroupName") ?? "").ToString();
                //var signUpStudentsSpecialityId = userControl_ReadIdCard1.TextValue;
                //if (String.IsNullOrEmpty(strGroupNo))
                //{
                //    DevHelper.ShowErrorMessageBox("请您选择该考生预约的组别！");
                //    return;
                //}
                //var actcount = this.gridView1.GetFocusedRowCellValue("ActualAcount") == null
                //    ? -1
                //    : Convert.ToInt32(this.gridView1.GetFocusedRowCellValue("ActualAcount").ToSafeString());
                //var totalcount = this.gridView1.GetFocusedRowCellValue("TotalAcount") == null
                //   ? 0
                //   : Convert.ToInt32(this.gridView1.GetFocusedRowCellValue("TotalAcount").ToSafeString());

                //if (actcount >= totalcount)
                //{
                //    DevHelper.ShowErrorMessageBox("该组人数已经预约满，请您选择其他预约组！");
                //    return;
                //}
                //if (String.IsNullOrEmpty(lbGuid.Text))
                //{
                //    DevHelper.ShowErrorMessageBox("请您输入或者扫描考生身份证号，并按回车键！");
                //    return;
                //}
                //if (!string.IsNullOrEmpty(lbYYZB.Text))
                //{
                //    DevHelper.ShowErrorMessageBox("该考生已经预约考试时间，信息如下：预约组-》" + lbYYZB.Text + "，预约时间-》" + lbYYSJ.Text + "。如需重新分配请先删除之前信息");
                //    return;
                //}
                //else
                //{
                //    lbYYZB.Text = gridView1.GetFocusedRowCellValue("GroupName").ToSafeString();
                //    lbYYSJ.Text = DateTime.Now.ToString();
                //    service.MakeAppointment_First(lbGuid.Text, strGroupNo);
                //    SaveIDCardInfo(SignUpID);
                //    InitAppointmentStudents();
                //    DataTable dtPrint = service.GetStudentAppointmentDataTable_Print(userControl_ReadIdCard1.TextValue, SessionerHelper.ExamPlaceID, SessionerHelper.SpecialityKindsNO, SessionerHelper.ExamLevel).Tables[0];
                //    if (dtPrint.Rows[0]["Sex"].ToSafeString() == "1")
                //    {
                //        dtPrint.Rows[0]["Sex"] = "男";
                //    }
                //    else
                //    {
                //        dtPrint.Rows[0]["Sex"] = "女";
                //    }
                //    Report_Print print = new Report_Print(dtPrint);
                //    print.Width = 800;
                //    print.ShowDialog();
                //    ClearTextBox();
                //}
            }
        }

        private void SaveIDCardInfo(string strSignUpID)
        {
            //try
            //{
            //    Image image = pictureBox1.Image;
            //    if (image != null && !string.IsNullOrEmpty(strSignUpID))
            //    {
            //        //string PicDataD = ImageConvertHelper.ToBase64String(pictureBox1.Image, System.Drawing.Imaging.ImageFormat.Bmp);
            //        //new ServiceControlDataSource().SaveAppointmentIdCard(strSignUpID, PicDataD);
            //    }
            //}
            //catch
            //{ }
        }

        private void gridView1_RowClick(object sender, RowClickEventArgs e)
        {
            InitAppointmentStudents();
        }

        #region 身份证读卡器
        private void FillData()
        {
            try
            {
                byte[] name = new byte[30];
                int length = 30;
                CheckIDCard.GetPeopleName(ref name[0], ref length);
                //MessageBox.Show();
                byte[] number = new byte[30];
                length = 36;
                CheckIDCard.GetPeopleIDCode(ref number[0], ref length);
                byte[] people = new byte[30];
                length = 3;
                CheckIDCard.GetPeopleNation(ref people[0], ref length);
                byte[] validtermOfStart = new byte[30];
                length = 16;
                CheckIDCard.GetStartDate(ref validtermOfStart[0], ref length);
                byte[] birthday = new byte[30];
                length = 16;
                CheckIDCard.GetPeopleBirthday(ref birthday[0], ref length);
                byte[] address = new byte[30];
                length = 70;
                CheckIDCard.GetPeopleAddress(ref address[0], ref length);
                byte[] validtermOfEnd = new byte[30];
                length = 16;
                CheckIDCard.GetEndDate(ref validtermOfEnd[0], ref length);
                byte[] signdate = new byte[30];
                length = 30;
                CheckIDCard.GetDepartment(ref signdate[0], ref length);
                byte[] sex = new byte[30];
                length = 3;
                CheckIDCard.GetPeopleSex(ref sex[0], ref length);
                txtIdCard.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(number).Replace("\0", "");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        #endregion

        private void timer_ReadID_Tick(object sender, EventArgs e)
        {
            try
            {
                //删除上次所拍的照片                
                if (System.IO.File.Exists(Application.StartupPath + "\\zp.bmp"))
                {
                    System.IO.File.Delete(Application.StartupPath + "\\zp.bmp");
                }

                if ((iRetCOM == 1) || (iRetUSB == 1))
                {
                    int authenticate = CheckIDCard.CVR_Authenticate();
                    if (authenticate == 1)
                    {
                        int readContent = CheckIDCard.CVR_Read_Content(4);
                        if (readContent == 1 || readContent == 2)
                        {
                            timer_ReadID.Enabled = false;
                            FillData();
                            CheckAppointmentStudents(txtIdCard.Text);
                            this.groupSFZ.Text = "设置、扫描区（读卡成功）";
                            timer_ReadID.Enabled = true;
                        }
                        else
                        {
                            this.groupSFZ.Text = "设置、扫描区（读卡操作失败）";
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox(ex.ToString());
            }
        }

        private void benQuery_Click(object sender, EventArgs e)
        {
            InitAppointmentStudents();
        }
    }
}
